<?php
/* tblMenu */
class Menu extends Form
	{
		protected $_CategoryID                 = array();
		protected $_CategoryName               = array();
		protected $_SubCategory                = array();
		protected $_SubCategoryID              = array();

		function __construct()
		{
			parent::__construct();
		}
		
		public function get_CategoryID()
		{
				return  $this->_get_CategoryIDValue();
		}

		private function _get_CategoryIDValue()
		{
			if(isset($this->_CategoryID['value']))
				return $this->_CategoryID['value'];
			else
				return false;
		}

		public function get_CategoryName()
		{
				return  $this->_get_CategoryNameValue();
		}

		private function _get_CategoryNameValue()
		{
			if(isset($this->_CategoryName['value']))
				return $this->_CategoryName['value'];
			else
				return false;
		}

		public function get_SubCategory()
		{
				return  $this->_get_SubCategoryValue();
		}

		private function _get_SubCategoryValue()
		{
			if(isset($this->_SubCategory['value']))
				return $this->_SubCategory['value'];
			else
				return false;
		}

		public function get_SubCategoryID()
		{
				return  $this->_get_SubCategoryIDValue();
		}

		private function _get_SubCategoryIDValue()
		{
			if(isset($this->_SubCategoryID['value']))
				return $this->_SubCategoryID['value'];
			else
				return false;
		}


		public function set_CategoryIDValue($strCategoryID)
		{
			if($this->validateInput("validateNumber", $strCategoryID, "CategoryID "))
					return($this->_setNewValue($this->_CategoryID, $strCategoryID));
			else
					return false;
		}

		public function set_CategoryNameValue($strCategoryName)
		{
			if($this->validateInput("validateAlphaNumericSpace", $strCategoryName, "CategoryName "))
					return($this->_setNewValue($this->_CategoryName, $strCategoryName));
			else
					return false;
		}

		public function set_SubCategoryValue($strSubCategory)
		{
			if($this->validateInput("validateAlphaNumericSpace", $strSubCategory, "SubCategory "))
					return($this->_setNewValue($this->_SubCategory, $strSubCategory));
			else
					return false;
		}

		public function set_SubCategoryIDValue($strSubCategoryID)
		{
			if($this->validateInput("validateNumber", $strSubCategoryID, "SubCategoryID "))
					return($this->_setNewValue($this->_SubCategoryID, $strSubCategoryID));
			else
					return false;
		}
		
	/**
	 * public function to search tblMenu
	 * @param any that are set in $this
	 * @return MySqlResults
	 */
	public function searchMenu()
	{
		$strJoin = " WHERE ";
		$strSql = "SELECT * 
                   FROM tblMenu ";

		if($this->_get_CategoryIDValue())
		{
			$strSql .= $strJoin." CategoryID = '".$this->_get_CategoryIDValue()."' ";
			$strJoin = " AND ";
		}

		if($this->_get_CategoryNameValue())
		{
			$strSql .= $strJoin." CategoryName = '".$this->_get_CategoryNameValue()."' ";
			$strJoin = " AND ";
		}

		if($this->_get_SubCategoryValue())
		{
			$strSql .= $strJoin." SubCategory = '".$this->_get_SubCategoryValue()."' ";
			$strJoin = " AND ";
		}

		if($this->_get_SubCategoryIDValue())
		{
			$strSql .= $strJoin." SubCategoryID = '".$this->_get_SubCategoryIDValue()."' ";
			$strJoin = " AND ";
		}


		$qrySearchtblMenu = new MySqlResults($strSql);
		return $qrySearchtblMenu;	
    }
    
    /**
     * display sub cats that contain current products 
     */
	public function searchMenuProductSubCat()
	{
		$strJoin = " AND ";
		$strSql = "SELECT DISTINCT tblCategory.ID CategoryID
						, tblCategory.Category CategoryName
						, tblSubCategory.SubCategory
						, tblSubCategory.ID SubCategoryID
						FROM tblCategory
						LEFT JOIN tblSubCategory ON 
						tblCategory.ID = tblSubCategory.Category
						LEFT JOIN tblSubCategoryAndProduct ON
						tblSubCategoryAndProduct.SubCategory = tblSubCategory.ID
						LEFT JOIN tblProduct ON 
						tblSubCategoryAndProduct.Product = tblProduct.ID 
						WHERE tblProduct.ID IS NOT NULL and tblProduct.Discontinued = 0 ";
						

		if($this->_get_CategoryIDValue())
		{
			$strSql .= $strJoin." CategoryID = '".$this->_get_CategoryIDValue()."' ";
			$strJoin = " AND ";
		}

		if($this->_get_CategoryNameValue())
		{
			$strSql .= $strJoin." tblCategory.Category = '".$this->_get_CategoryNameValue()."' ";
			$strJoin = " AND ";
		}

		if($this->_get_SubCategoryValue())
		{
			$strSql .= $strJoin." SubCategory = '".$this->_get_SubCategoryValue()."' ";
			$strJoin = " AND ";
		}

		if($this->_get_SubCategoryIDValue())
		{
			$strSql .= $strJoin." SubCategoryID = '".$this->_get_SubCategoryIDValue()."' ";
			$strJoin = " AND ";
		}

		$strSql .= "ORDER BY CategoryName, SubCategory ";
		$qrySearchtblMenu = new MySqlResults($strSql);
		//print_object($qrySearchtblMenu);
		return $qrySearchtblMenu;	
    }
}

?>